<template>
  <svg aria-hidden="true" class="cp-icon">
    <use :href="symbolId" :fill="color" />
  </svg>
</template>

<script lang="ts">
import { defineComponent, computed } from 'vue'

export default defineComponent({
  name: 'SvgIcon',
  props: {
    prefix: {
      type: String,
      default: 'icon'
    },
    name: {
      type: String,
      required: true
    },
    color: {
      type: String,
      default: '#333'
    }
  },
  setup(props) {
    const symbolId = computed(() => `#${props.prefix}-${props.name}`)
    return { symbolId }
  }
})
</script>

<style>
.cp-icon {
  /* rem 始终参照 html 的font-size  */
  /* em 参照父元素   实际转换大小 当前的font-size* em   */
  width: 1em;
  height: 1em;
}
</style>
